package dltec.Test;

public class WorkerArrayTest {

	public static void main(String[] args) {
		
		Worker[] worker = new Worker[3];	
		Worker w1 = new Worker("张三",25);
		Worker w2 = new Worker("李四",35);
		Worker w3 = new Worker("王五",55);
		
		worker[0] = w1;
		worker[1] = w2;
		worker[2] = w3;
		
		for (int i = 0; i < worker.length; i++) {
			worker[i].work();
		}
		
		System.out.println(oldWorker(worker));
	}
	
	public static Worker oldWorker(Worker[] worker){
		
		int old = worker[0].getAge();
		int index = 0;
		for (int i = 0; i < worker.length; i++) {
			if(old < worker[i].getAge()){
				old = worker[i].getAge();
				index = i;
			}
		}
		
		return worker[index];
		
	}

}
